﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sunny.UI;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// SunnyUI 弹窗
    /// </summary>
    public static class DialogHelper
    {
        #region 密码输入框
        public static bool InputPasswordDialog(ref string value, bool checkEmpty = true, string desc = "请输入密码：", UIStyle style = UIStyle.Blue, bool topMost = false, bool showMask = false)
        {
            UIInputForm uIInputForm = new UIInputForm();
            uIInputForm.TopMost = topMost;
            uIInputForm.Style = style;
            uIInputForm.Text = UILocalize.InputTitle;
            uIInputForm.Label.Text = desc;
            uIInputForm.Editor.PasswordChar = '*';
            uIInputForm.CheckInputEmpty = checkEmpty;
            if (showMask)
            {
                uIInputForm.ShowDialogWithMask();
            }
            else
            {
                uIInputForm.ShowDialog();
            }

            if (uIInputForm.IsOK)
            {
                value = uIInputForm.Editor.Text;
                return true;
            }

            return false;
        }

        public static bool InputPasswordDialog(this UIForm form, ref string value, bool checkEmpty = true, string desc = "请输入密码：", bool showMask = false)
        {
            return InputPasswordDialog(ref value, checkEmpty, desc, form?.Style ?? UIStyle.Blue, form?.TopMost ?? false, showMask);
        }

        public static bool InputPasswordDialog(this UIPage form, ref string value, bool checkEmpty = true, string desc = "请输入密码：", bool showMask = false)
        {
            return InputPasswordDialog(ref value, checkEmpty, desc, form?.Style ?? UIStyle.Blue, form?.TopMost ?? false, showMask);
        }

        public static bool InputPasswordDialog(this Form form, ref string value, bool checkEmpty = true, string desc = "请输入密码：", UIStyle style = UIStyle.Blue, bool showMask = false)
        {
            return InputPasswordDialog(ref value, checkEmpty, desc, style, form?.TopMost ?? false, showMask);
        }
        #endregion
    }
}
